package com.lenovo.spider.process.pipeline;

import com.lenovo.spider.process.TaskProcess;
import com.lenovo.spider.domain.ResultItem;
import com.lenovo.spider.domain.Task;
import lombok.extern.slf4j.Slf4j;

/**
 * @author <a href="mailto:liuhan3@lenovo.com">HanL(liuhan3)</a>
 * on 2018/3/21 18:33
 */
@Slf4j
public abstract class Pipeline implements TaskProcess {

    public Task pipeline(Task task) {
        return doIf(Task::isSuccess, t -> {
            if (task.getItem() != null) {
                pipeline(task.getItem());
            }
            return t;
        }).apply(task);
    }

    abstract void pipeline(ResultItem item);
}
